﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace IISLogAnalysis.Business
{
    public class RunLogParserExe
    {
        public static void RunLogParser(string query,string args)
        {
            Process process = new Process();
            process.StartInfo.FileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logparser.exe"); //string.Format("{0}\\LogParser.exe",AppDomain.CurrentDomain.BaseDirectory);
            process.StartInfo.Arguments = string.Format("\"{0}\" {1}",query,args);
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo.ErrorDialog = true;
            process.Start();
            process.WaitForExit();
        }

        public static void RunNotepad(string args)
        {
            Process process = new Process();
            process.StartInfo.FileName = "notepad.exe";
            process.StartInfo.Arguments = args;
            process.Start();
        }

        public static List<string> ReadResult(string path)
        {
            List<string> list = new List<string>();

            StreamReader sr = File.OpenText(path);

            string line;
            while ((line=sr.ReadLine())!=null)
            {
                list.Add(line);
            }

            return list;
        }

    }
}
